<template>
  <div class="contentCate">
    <el-card class="box-card" v-if="status === 'index'">
      <el-row>
        <el-select
          v-model="searchParams.id"
          clearable
          placeholder="请选择盲盒"
          style="width:200px"
          size="mini"
        >
          <el-option
            v-for="item in blindBox"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
        <!-- <el-input
          v-model="searchParams.id"
          clearable
          placeholder="请输入盲盒id"
          style="width:200px"
          size="mini"
        ></el-input> -->
        <!-- <el-date-picker
          v-model="searchParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择起始时间"
          size="mini"
          style="width:150px"
        ></el-date-picker>
        <el-date-picker
          v-model="searchParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间"
          size="mini"
          style="width:150px"
        ></el-date-picker> -->
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getData"
          v-if="has('feedback/index')"
          >搜索</el-button
        >
      </el-row>
      <el-table
        :data="data.data"
        v-loading="table_loading"
        row-key="id"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="250px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.blind_box_prize_image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.blind_box_prize_image)"
              />
              <div>
                <div>赏品ID：{{ scope.row.blind_box_prize_id }}</div>
                <div>{{ scope.row.blind_box_prize_name }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.blind_box_prize_level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.blind_box_prize_level_name }}
            </span>
          </template>
        </el-table-column>

        <el-table-column prop="total" label="总数" align="center">
        </el-table-column>

        <el-table-column prop="level_name" label="实际概率" align="center">
          <template slot-scope="scope">
            <span> {{ ((scope.row.total / data.c) * 100).toFixed(2) }}% </span>
          </template>
        </el-table-column>
        <el-table-column prop="probability" label="设置概率" align="center">
          <template slot-scope="scope">
            <span> {{ scope.row.probability }}% </span>
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="searchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="data.total"
        @size-change="changeSize"
        @current-change="changePage"
      ></el-pagination> -->
    </el-card>
  </div>
</template>

<script>
import api from "../../api/api.js";
export default {
  name: "contentCate",
  data() {
    return {
      status: "index", // 页面控制
      data: [], // 表格诗句
      table_loading: false, // 表格加载中
      loading: false, //全局加载中
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      searchParams: {
        page: 1,
        limit: 10,
        mobile: "",
        userId: ""
      },
      activeValue: 1,
      inactiveValue: 0,
      blindBox: []
    };
  },
  created() {
    // this.getData();
    this.getBox();
  },

  methods: {
    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    // 取消加载
    unload() {
      this.loading.close();
    },
    getBox() {
      api.common
        .blindBox()
        .then(res => {
          if (res.data.code === 200) {
            this.blindBox = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    changeStatus(e) {
      this.load();
      api.feedback
        .status(e.id, { status: e.status })
        .then(res => {
          this.unload();
          if (res.data.code === 200) {
            this.$message.success("保存成功");
            this.init();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.userRanks
        .box({ params: this.searchParams })
        .then(res => {
          if (res.data.code == 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 重置搜索参数重新搜索
    reset() {
      this.init();
      this.getData();
    },
    // 初始化
    init() {
      this.searchParams.page = 1;
      this.searchParams.mobile = "";
      this.searchParams.userId = "";
    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    }
  }
};
</script>

<style scoped lang="less">
.contentCate {
  margin: 0 auto;
  .search {
    margin: 0 auto 10px auto;
  }
}
</style>
